remove spaces from string python

26

## Remove the Starting Spaces in Python
 
string1="    This is Test String to strip leading space"
print (string1.lstrip())
sentence = ' hello  apple'
sentence.strip()
>>> 'hello  apple'
s = '  Hello   World     From  Pankaj  \t\n\r\t  Hi       There        '

>>> s.replace(" ", "")
'HelloWorldFromPankaj\t\n\r\tHiThere'

Comments

Submit
0 Comments